import { Vec2 } from "cc";
import { AdHorizontal } from "./AdHorizontal";
import { AdVertical } from "./AdVertical";


export class BannerOptions {

    public Horizontal: AdHorizontal = AdHorizontal.NONE;
    public Vertical: AdVertical = AdVertical.NONE;
    public Offset: Vec2 = Vec2.ZERO;

    public Top: number = 0;

    public Left: number = 0;

    public _width: number = 300;
    public _height: number = 96;
    public get Width() {
        return this._width;
    }
    public get Height() {
        return this._height;
    }
    public set Width(value) {
        this._width = value;
    }
    public set Height(value) {
        this._height = value;
    }
    public static New(horizontal: AdHorizontal, vertical: AdVertical, offset: Vec2, left: number, top: number): BannerOptions {
        var options = new BannerOptions();
        options.Horizontal = horizontal;
        options.Vertical = vertical;
        if (offset)
            options.Offset = offset;
        else
            options.Offset = Vec2.ZERO;
        options.Left = left;
        options.Top = top;
        return options;
    }

    constructor() {
        this.Horizontal = AdHorizontal.CENTER;
        this.Vertical = AdVertical.BOTTOM;
        this.Width = this.DefaultWidth();
    }



    public DefaultWidth() {

        // var isLandscape = Screen.width > Screen.height;
        // return isLandscape ? 300 : 300;
        return 300;
    }

    public getBannerStyle(wxsys: any): { left: number, top: number, width: number, height: number } {

        var horizontal = this.Horizontal;
        var vertical = this.Vertical;

        let windowWidth = wxsys.windowWidth;
        let windowHeight = wxsys.windowHeight;
        let top = 0;
        let left = 0;

        switch (vertical) {
            case AdVertical.TOP:
                top = 0;
                break;
            case AdVertical.CENTER:
                top = (windowHeight - this.Height) / 2;
                break;
            case AdVertical.BOTTOM:
                top = windowHeight - this.Height;
                break;
            case AdVertical.CUSTOM:
            default:
                top = this.Top;
                break;
        }
        switch (horizontal) {
            case AdHorizontal.LEFT:
                left = 0;
                break;
            case AdHorizontal.CENTER:
                left = (windowWidth - this.Width) / 2;
                break;
            case AdHorizontal.RIGHT:
                left = windowWidth - this.Width;
                break;
            case AdHorizontal.CUSTOM:
            default:
                left = this.Left;
                break;
        }

        return {
            left: (left + this.Offset.x),
            top: (top + this.Offset.y),
            width: this.Width,
            height: this.Height,
        };
    }


}